#!/usr/bin/env bash
# Usage: sbtenv version-file-write <file> <version>

set -e
test -n "${SBTENV_DEBUG}" && set -x

SBTENV_VERSION_FILE="${1}"
SBTENV_VERSION="${2}"

if [ -z "${SBTENV_VERSION}" ] || [ -z "${SBTENV_VERSION_FILE}" ]; then
  sbtenv-help --usage version-file-write >& 2
  exit 1
fi

# Make sure the specified version is installed.
sbtenv-prefix "${SBTENV_VERSION}" > /dev/null

# Write the version out to disk.
echo "${SBTENV_VERSION}" > "${SBTENV_VERSION_FILE}"

